;/////////////////////////////////////////////////////////////;
;                                                             ;
;                SimpleDX11 Texture Procedures                ;
;                                                             ;
;                                                             ;
;                   (c) 2013 SimpleDX Team                    ;
;                                                             ;
;                         License: MIT                        ;
;                                                             ;
;/////////////////////////////////////////////////////////////;


;-//    Private structures    //
Structure Texture_Template
  *vTable
  *p.Texture
  *SD3D.Screen3D
  *Device.ID3D11Device
  
  File.s
  Texture.ID3D11ShaderResourceView
  Texture2D.ID3D11Texture2D
  TextureInfo.D3D11_TEXTURE2D_DESC 
   
EndStructure


;-//    Constructor    //
Procedure New_Texture(*SD3D.Screen3D)
  Protected *this.Texture_Template
 
  *this = AllocateMemory(SizeOf(Texture_Template))
  InitializeStructure(*this, Texture_Template)
  
  If *this
    *this\vTable  = ?Texture_Class    
    *this\p       = *this
    *this\SD3D     = *SD3D  
    *this\Device  = *this\SD3D\GetDevice()

*this\Texture2D = #Null
    ProcedureReturn *this
  EndIf  
  ProcedureReturn #False
EndProcedure



;-//    Public procedures    //

Procedure Texture_CreateTextureFromFile(*this.Texture_Template, File.s)
  Protected Result.l = #S_OK
  Protected *FileStr = StringToByteString(File)  
  
  Select FileSize(File) 
    Case -1
      ProcedureReturn -1
    Case -2 
      ProcedureReturn -2
    Default
      
  EndSelect
  ;D3DX11CreateShaderResourceViewFromMemory(*this\Device, ImgID, 1024, #Null, #Null, @*this\Texture, #Null)
  Result = D3DX11CreateShaderResourceViewFromFileA(*this\Device, *FileStr, #Null, #Null, @*this\Texture, #Null)  
  
    *this\Texture\GetResource(@*this\Texture2D)  
    Result = *this\Texture2D\GetDesc(@*this\TextureInfo) 
    *this\Texture2D\Release()

    
  
  ProcedureReturn Result
EndProcedure

Procedure Texture_GetTexture(*this.Texture_Template)
  ProcedureReturn *this\Texture
EndProcedure

Procedure Texture_GetInfo(*this.Texture_Template)
  ProcedureReturn *this\TextureInfo
EndProcedure


Procedure Texture_Release(*this.Texture_Template)
  If *this\Texture : *this\Texture\Release() : EndIf  
  FreeMemory(*this)
EndProcedure

;-//    Private procedures    //

;/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
;/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
;/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
;/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
;/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
;-//    DataSection    //
DataSection
  Texture_Class:
  Data.i @Texture_CreateTextureFromFile()
  Data.i @Texture_GetTexture()
  Data.i @Texture_GetInfo()
  Data.i @Texture_Release()  
EndDataSection
; IDE Options = PureBasic 5.20 beta 14 LTS (Windows - x64)
; CursorPosition = 43
; FirstLine = 35
; Folding = -
; EnableXP
; EnableCompileCount = 0
; EnableBuildCount = 0